package org.sean.framework.validator;

import org.sean.framework.code.StatusInfo;
import org.sean.framework.exception.StatusException;
import org.sean.framework.util.NumberUtil;
import org.sean.framework.util.ObjectUtil;
import org.sean.framework.util.StringUtil;

/**
 * 数据校验
 */
public final class Assert {

    private Assert() {
    }

    public static void isBlank(String str, String message) {
        if (StringUtil.isBlank(str)) {
            throw new StatusException(StatusInfo.paramsInvalidError().setAnyMessage(message));
        }
    }

    public static void isNull(Object object, String message) {
        if (object == null) {
            throw new StatusException(StatusInfo.paramsInvalidError().setAnyMessage(message));
        }
    }

    public static void isValidId(Long id, String message) {
        if (NumberUtil.isValidId(id)) {
            throw new StatusException(StatusInfo.paramsInvalidError().setAnyMessage(message));
        }
    }

    public static void isValidId(Integer id, String message) {
        if (NumberUtil.isValidId(id)) {
            throw new StatusException(StatusInfo.paramsInvalidError().setAnyMessage(message));
        }
    }

    public static void isEmpty(Object object, String message) {
        if (ObjectUtil.isEmpty(object)) {
            throw new StatusException(StatusInfo.paramsInvalidError().setAnyMessage(message));
        }
    }

}
